//
//  TMdownview.swift
//  GZWeibo007
//
//  Created by myd on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit
protocol chilkoperatebutton
{
    func chilkoperatebutton(titlestr : String)
}
class TMdownview: UIView {
    var delega : chilkoperatebutton?
    
    let review = UIButton()
    
    let relay = UIButton()
    
    let support = UIButton()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setview()
        setmessage()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func setmessage()
    {
        setbutton(review, title: "评论")
        review.addTarget(self, action: "chilkreview", forControlEvents: UIControlEvents.TouchUpInside)
        setbutton(relay, title: "转发")
        relay.addTarget(self, action: "chilkrelay", forControlEvents: UIControlEvents.TouchUpInside)
        setbutton(support, title: "赞")
        support.addTarget(self, action: "chilksupport", forControlEvents: UIControlEvents.TouchUpInside)
    }
    func chilkreview()
    {
        presen("评论")
    }
    func chilkrelay()
    {
        presen("转发")
    }
    func chilksupport()
    {
        
    }
    func presen(title:String)
    {
        delega?.chilkoperatebutton(title)
        
    }
    
    func setbutton(btn : UIButton , title : String)
    {
        btn.setTitle(title, forState: UIControlState.Normal)
        btn.setTitleColor(UIColor.grayColor(), forState: UIControlState.Normal)
        btn.backgroundColor = UIColor.whiteColor()
        btn.titleLabel?.font = UIFont.systemFontOfSize(11)
        btn.titleLabel?.textAlignment = NSTextAlignment.Center
    }
    func setview()
    {
        addSubview(review)
        addSubview(relay)
        addSubview(support)
        review.translatesAutoresizingMaskIntoConstraints = false
        relay.translatesAutoresizingMaskIntoConstraints = false
        support.translatesAutoresizingMaskIntoConstraints = false
        
        addConstraint(NSLayoutConstraint(item: review, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Left, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: review, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: review, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier:1, constant: 0))
        addConstraint(NSLayoutConstraint(item: review, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Width, multiplier:1/3, constant: 0))
        
        addConstraint(NSLayoutConstraint(item: relay, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: review, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: relay, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: relay, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier:1, constant: 0))
        addConstraint(NSLayoutConstraint(item: relay, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Width, multiplier:1/3, constant: 0))
        
        addConstraint(NSLayoutConstraint(item: support, attribute: NSLayoutAttribute.Left, relatedBy: NSLayoutRelation.Equal, toItem: relay, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: support, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0))
        addConstraint(NSLayoutConstraint(item: support, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier:1, constant: 0))
        addConstraint(NSLayoutConstraint(item: support, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Width, multiplier:1/3, constant: 0))
        
    }
    
}
